﻿#ifndef LINE_OBJECT_H
#define LINE_OBJECT_H
#include "plug_item.h"
#include "socket_item.h"

class Line_Object : public QGraphicsLineItem
{
public:
    enum {Type = UserType + 6};
    Line_Object(PlugObject* startItem, SocketObject* endItem, Line_Object* parent = nullptr);
    ~Line_Object();

    int type() const override
    {
        return Type;
    }

    //外部接口，用于获得车上具体的信息
    PlugObject* getStartItem() const
    {
        return myStartItem;
    }
    SocketObject* getEndItem() const
    {
        return myEndItem;
    }
    QString getLineState()
    {
        judgeLineState();
        return  lineState;
    }
    bool gethasSendtheSocketisAtOrigin() const
    {
        return hasSendtheSocketisAtOrigin;
    }
    void changehasSendtheSocketisAtOrigin()
    {
        hasSendtheSocketisAtOrigin = true;
    };

    //颜色改变的函数
    void mLCtoMove()
    {
        mylinecolor = Color_Similar;    //运动标志 ，对接、断开中
        isMoving = true;
        isConnected = false;
    }
    void IsConnecting()
    {
        isConnecting = true ;    //连接中
        isDisConnnecting = false ;
    }
    void IsDisCnting()
    {
        isConnecting = false ;    //断连中
        isDisConnnecting = true;
    }
    void mLCtoCnted()
    {
        mylinecolor = Color_Connected ;    //连接完成
        isConnected = true;
        isMoving = false;
    }



protected:
    QRectF boundingRect() const Q_DECL_OVERRIDE;
    QPainterPath shape() const override;
    void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) Q_DECL_OVERRIDE;
    virtual void drawSelectedRect(QPainter* painter); //画虚线框

private:
    void  judgeLineState();

private:
    PlugObject* myStartItem;
    SocketObject* myEndItem;

    QPolygonF arrowHead;
    QColor mylinecolor;

    QColor Color_Similar;
    QColor Color_Connected;

    bool isMoving;
    bool isConnecting;
    bool isDisConnnecting;
    bool isConnected;

    QString lineState;

    //插座信心已发送标志
    bool hasSendtheSocketisAtOrigin = false;


};

#endif // LINE_OBJECT_H
